package com.zxx.flowerstore.controller;

import com.zxx.flowerstore.entity.FlowerProvinces;
import com.zxx.flowerstore.entity.enums.ResultEnum;
import com.zxx.flowerstore.service.ProvinceService;
import com.zxx.flowerstore.utils.common.MyException;
import com.zxx.flowerstore.utils.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ProvinceController
 * @Author zhanghaorui
 * @Date 2021/3/30 9:42 上午
 * @Description ProvinceController
 * @Version 1.0
 */
@RequestMapping("/province")
@RestController
@CrossOrigin
public class ProvinceController {

    private static final Logger logger = LoggerFactory.getLogger(ProvinceController.class);

    @Autowired
    private ProvinceService provinceService;

    @PostMapping("/selectProvinces")
    @ResponseBody
    public Result selectProvinces(@RequestBody FlowerProvinces flowerProvinces) {
        try {
            return provinceService.selectProvinces(flowerProvinces);
        } catch (MyException me) {
            logger.info(me.getMessage());
            return Result.error(ResultEnum.ERROR.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info("选择省市区:"+e.getMessage());
            return Result.error(ResultEnum.ERROR.getCode(), "查询失败");
        }
    }

}
